from django.db import models
from frame_server.model import BaseModel


'''部门'''
class Dept(BaseModel):
    deptName = models.CharField(max_length=255, unique=True, db_column="dept_name", verbose_name="部门名")
    fullName = models.CharField(max_length=255, db_column="full_name",null=True,blank=True, verbose_name="部门全称")
    sort = models.PositiveIntegerField(null=True,blank=True, verbose_name="排序")
    parentId = models.ForeignKey(to='self', db_column="parent_id", on_delete=models.CASCADE, db_constraint=False, null=True,blank=True, verbose_name="父级id")
    remark = models.CharField(max_length=255,null=True,blank=True, verbose_name="备注")
    
    class Meta:
        db_table = 'system_dept'
        indexes = [
            models.Index(fields=['deptName']),
            models.Index(fields=['fullName']),
        ]
    
    def __str__(self):
        return self.deptName
    
# 用户多对多关联部门
class UserDept(BaseModel):
    user = models.ForeignKey(to="user.User", db_column="user_id", db_constraint=False, on_delete=models.CASCADE, null=True,blank=True, verbose_name="用户id")
    dept = models.ForeignKey(Dept, db_column="dept_id", db_constraint=False, on_delete=models.CASCADE, null=True,blank=True, verbose_name="部门id")
    class Meta:
        db_table = 'system_user_dept'